package com.googlecode.flealancemarket.service.commands.impl;

import com.googlecode.flealancemarket.core.tapestry.SpringBean;
import com.googlecode.flealancemarket.metamodel.User;
import com.googlecode.flealancemarket.metamodel.beans.UserBean;
import com.googlecode.flealancemarket.service.commands.GetUserByUsername;
import com.googlecode.flealancemarket.service.facades.UserFacade;
import java.util.List;
import org.apache.tapestry.ioc.annotations.Inject;

/**
 *
 * @author vanja
 */
public class GetUserByUsernameImpl implements GetUserByUsername {

    private String username;
    private UserFacade facade;

    private User example;
    public User getExample(){
        return example;
    }
    public void setExample(User e){
        example = e;
    }

    public User execute() {

        example.setUsername(username);
        List<User> list = facade.getUserByExample(example);
        return list.isEmpty() ? null : list.get(0);
    }


    public UserFacade getFacade() {
        return facade;
    }

    public void setFacade(UserFacade facade) {
        this.facade = facade;
    }

    public void setUsername(String username) {
        this.username = username;
    }

}
